package com.example.smartcity_poverty.ui.SmartSubject

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.ui.SmartSubject.Adapter.SubjectHomeRvAdapter
import kotlinx.android.synthetic.main.fragment_subject_home.*


/**
 * 限选主题合集 -
 */
class SubjectHomeFragment : Fragment() {

    private lateinit var mAdapter: SubjectHomeRvAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_subject_home, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        setAdapter()
        mUpdateAdapter()
    }

    /**
     * 列表适配器
     */
    private fun setAdapter() {
        mAdapter = SubjectHomeRvAdapter(SetSubjectData.getSubjectArray, R.layout.re_subject_item)

        SubjectHomeRv.apply {
            this.isNestedScrollingEnabled = false
            this.layoutManager = LinearLayoutManager(context)
            this.adapter = mAdapter
        }
    }

    /**
     * 刷新数据
     */
    private fun mUpdateAdapter() = mAdapter.notifyDataSetChanged()

}